package com.kingmed.kmss.admin.modules.sys.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kingmed.kmss.admin.modules.sys.model.SysOpenGroup;
import com.kingmed.kmss.admin.modules.sys.service.ISysOpenGroupService;
import com.kingmed.kmss.common.vo.CommonPage;
import com.kingmed.kmss.common.vo.CommonResponse;
import com.kingmed.kmss.common.vo.CommonResponseHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 对外授权组
 * 
 * @author Sys
 * @date 2022-12-16
 */
@RestController
@RequestMapping("/sys/open/group")
@Api(tags = "sys对外授权组")
public class SysOpenGroupController
{
    @Autowired
    private ISysOpenGroupService sysOpenGroupService;

    /**
     * 查询对外授权组列表
     */
    @ApiOperation("查询对外授权组列表")
    @GetMapping("/list")
    public CommonResponse<CommonPage<SysOpenGroup>> list(SysOpenGroup sysOpenGroup,
                                                         @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                         @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum)
    {

        Page<SysOpenGroup> list = sysOpenGroupService.list(sysOpenGroup, pageNum, pageSize);
        return CommonResponseHelper.success(CommonPage.restPage(list));
    }



    /**
     * 获取对外授权组详细信息
     */
    @ApiOperation("获取对外授权组详细信息")
    @GetMapping(value = "/{groupId}")
    public CommonResponse<SysOpenGroup> getInfo(@PathVariable("groupId") String groupId)
    {
        return CommonResponseHelper.success(sysOpenGroupService.selectSysOpenGroupByGroupId(groupId));
    }

    /**
     * 新增对外授权组
     */
    @ApiOperation("新增对外授权组")
    @PostMapping("/add")
    public CommonResponse<Boolean> add(@RequestBody SysOpenGroup SysOpenGroup)
    {
        return CommonResponseHelper.success(sysOpenGroupService.insertSysOpenGroup(SysOpenGroup));
    }

    /**
     * 修改对外授权组
     */
    @ApiOperation("修改对外授权组")
    @PutMapping("/edit")
    public CommonResponse<Boolean> edit(@RequestBody SysOpenGroup SysOpenGroup)
    {
        return CommonResponseHelper.success(sysOpenGroupService.updateSysOpenGroup(SysOpenGroup));
    }

    /**
     * 删除对外授权组
     */
    @ApiOperation("删除对外授权组")
	@DeleteMapping("/remove/{groupIds}")
    public CommonResponse<Boolean> remove(@PathVariable String[] groupIds)
    {
        return CommonResponseHelper.success(sysOpenGroupService.deleteSysOpenGroupByGroupIds(groupIds));
    }
}
